
package com.sig;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.sig.formes.Layer;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class LayerEnablerAdapter extends BaseAdapter{

	Map<String,Layer> layers=null;
	List<Layer> layers_by_position=null;
	LayoutInflater inflater;
	Context _context;

	public LayerEnablerAdapter(Context context,Map<String,Layer> layers)
	{
		inflater = (LayoutInflater)context.getSystemService
				(Context.LAYOUT_INFLATER_SERVICE);
		this._context = context;
		this.layers = layers;

		this.layers_by_position = new ArrayList<Layer>(layers.entrySet().size());
		for(Entry<String, Layer> e : this.layers.entrySet())
		{
			if((e.getValue()).getParam().CanBeDisable())			
				this.layers_by_position.add((Layer) e.getValue());

		}
	}


	public List<Layer> getLayers(){
		return layers_by_position;
	}

	@Override
	public int getCount() {
		if(this.layers != null)
		{
			return this.layers_by_position.size();
		}
		return 0;
	}

	@Override
	public Object getItem(int position) {
		return this.layers_by_position.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = inflater.inflate(R.layout.slider_layer_enabler, null);
		new SliderEnabler(this._context, (Layer)this.getItem(position), v );
		return v;
	}

}
